#pragma once

#include "include.h"
#include "XYLib/xy_map.h"

USING_NS_CC;

class GameMain;
class GameMap : public cocos2d::Layer {
	friend class GameMain;
public:
	GameMap();
	virtual	~GameMap();
	CREATE_FUNC(GameMap);
protected:
	virtual bool	init();
	virtual	void	update(float dt);

	void			onMouseLButtionDown(int x, int y);
	void			onMouseLButtionUp(int x, int y);
	void			onMouseRButtionDown(int x, int y);
	void			onMouseRButtionUp(int x, int y);

	Vec2			viewToWorld(int x, int y);
	Vec2			worldToView(int x, int y);

	bool			playerMove(int x, int y);

	bool	loadMap(const char* fileName);
	void	freeMap(void);
private:
	cocos2d::Image*		getImage(uint32_t index);
	XY_Map			_map;
	uint32_t		_leftPos;
	uint32_t		_topPos;
	Layer*			_layer;
	Animate*		_clickAni;
	bool			_lBtnDown;
	float			_lBtnDelta;
	float			_lDelta;
	bool			_update;
};